package cn.edu.fzu.homemaking.sso.service.impl;

import cn.edu.fzu.homemaking.exception.ServiceException;
import cn.edu.fzu.homemaking.sso.domain.entity.Company;
import cn.edu.fzu.homemaking.sso.domain.enums.StatusEnum;
import cn.edu.fzu.homemaking.sso.mapper.CompanyMapper;
import cn.edu.fzu.homemaking.sso.service.CompanyService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class CompanyServiceImpl implements CompanyService {

    @Resource
    private CompanyMapper companyMapper;

    @Override
    public Long add(String name, String creditCode, String legalPerson, String businessLicense, String contact,
                    String phone, Long areaId, String companyAddress) {

        Company company = companyMapper.getByCreditCode(creditCode);
        if (company != null) {
            throw new ServiceException("公司已经被注册");
        }
        //默认公司为禁止状态，只有管理员审核之后公司人员才能登录
        Company build = Company.build(name, creditCode, legalPerson, businessLicense, contact, phone, areaId,companyAddress,StatusEnum.BAN);
        companyMapper.insert(build);
        return build.getId();
    }
}
